package files;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;



public class XMLTools {

	public static void encodeToFile(Object object, String fileName) throws FileNotFoundException{
		XMLEncoder xe = new XMLEncoder(new FileOutputStream(fileName));

		try{
			xe.writeObject(object);
			xe.flush();
		}
		finally{
			xe.close();
		}
	}


	public static Object decodeFromFile(String fileName) throws FileNotFoundException, IOException{

		Object object = null;

		XMLDecoder xd = new XMLDecoder(new FileInputStream(fileName));

		try{
			object = xd.readObject();
		}
		finally{
			xd.close();
		}

		return object;
	}

}
